<template>
    <div class="index_b">
        <div>
            <v-header ref="header" @into="goto('mindex')"></v-header>
            <div class="indexbox" :style="{height:docHeight}" ref="box">
                <div class="index">
                    <div class="index_card" @click="clickQrcode()">
                        <img src="../assets/business/index1.png" alt="" class="hx_img">
                        <div class="index_title">核销</div>
                    </div>
                    <div class="index_card" @click="goto('mopencard')">
                        <img src="../assets/business/index2.png" alt="" class="hx_img">
                        <div class="index_title">开卡</div>
                    </div>
                </div>
            </div>
            <v-footer title="1" ref="footer" @into="goto('mmy')"></v-footer>
        </div>
    </div>
</template>
<script>
import header from './common/mheader'
import footer from './common/mfooter'
import getUrlParam from '../../store/modules/getUrlParam'
import cookie from '../../store/modules/cookie'
import wx from 'weixin-js-sdk'
    export default {
        components: {
            'v-header': header,
            'v-footer': footer
        },
        data () {
            return {
                docHeight: '',
                headerHeight:0,
                footerHeight:0,
                success:false,
                isRegister:false,
                msg:'',
                merid:"5"
            }
        },
        mounted () {
            this.headerHeight = this.$refs.header.$refs.headerbox.offsetHeight
            this.footerHeight = this.$refs.footer.$refs.footerbox.offsetHeight
            this.docHeight = (document.documentElement.clientHeight-this.headerHeight-this.footerHeight)+'px'
        },
        methods: {
            goto(path){
                this.$router.push({
                    path:'/'+path,
                })
            },
            clickQrcode(){
                var index = this.$indicator.open({spinnerType: 'fading-circle'});
                let that = this
                let openid = cookie.getCookie('openid')
                let url = window.location.href.split('#')[0]
                that.$http.get('merchant/Scanqrcode/index',{url:url}).then((res)=>{
                    if(res.code == 0){
                        wx.config({
                            debug: false,
                            appId: res.data.appId,
                            timestamp: res.data.timestamp,
                            nonceStr: res.data.nonceStr,
                            signature: res.data.signature,
                            jsApiList: ['scanQRCode']
                        });
                        wx.ready(function(){
                            wx.scanQRCode({
                                needResult: 1,
                                scanType: ["qrCode","barCode"],
                                success: function (re) {
                                    that.$indicator.close(index);
                                    let result = re.resultStr
                                    that.$http.get('merchant/Verification/scan',{vcode:result,openid:openid}).then((ret)=>{
                                        if(ret.code == 0){
                                            // that.$messagebox({title:'提示',message:ret.msg+'这是传的值'+that.merid+';'+result})
                                            that.$router.push({
                                                path:'/mverification',
                                                query:{
                                                    type:1,
                                                    msg:ret.msg,
                                                    distcount:ret.data.distcount,
                                                    time:ret.data.time,
                                                    card_no:ret.data.card_no
                                                }
                                            })
                                        }else if(ret.code ==-1){
                                            // that.$messagebox({title:'提示走核销失败',message:ret.msg+'这是传的值'+that.merid+';'+result})
                                           that.$router.push({
                                                path:'/mverification',
                                                query:{
                                                    type:2,
                                                    msg:ret.msg,
                                                    tel:ret.data.tel
                                                }
                                            })
                                        }else{
                                            that.$messagebox(ret.msg)
                                        }
                                    }).catch((ret)=>{
                                        that.$messagebox(ret.msg)
                                    })
                                }
                            });
                        });
                        wx.error(function(res){
                            that.$indicator.close(index);
                            that.$messagebox(res.msg);
                        });
                    }else{
                    }
                })
            },
        }
    }
</script>
<style scoped>
.indexbox{
    padding: 0 61px;
    background: #000;
}
.index{
    background: #fff;
    text-align: center;
    padding: 135px 75px;
    box-sizing: border-box;
}
.hx_img{
    width: 190px;
    height: 190px;
}
.index_card:nth-child(1){
    border-bottom: 1px solid #7A7A7A;
    padding-bottom: 85px;
}
.index_card:nth-child(2){
    padding-top: 93px;
}
.index_title{
    font-size: 74px;
    padding-top:30px;
    color: #000000;
}
.hz{
    color: #FF5722;
    font-size: 48px;
    text-align: center;
    padding: 100px 0;
}
</style>
